export default {
  state: {
    cartList: [],
  },
  mutations: {
    JOIN_CART(state, payload) {
      const info = state.cartList.find((v) => v.id === payload.id)
      if (info) {
        info.buyNum++
      } else {
        state.cartList = [
          {
            id: payload.id,
            goodsName: payload.goodsName,
            goodsPrice: payload.goodsPrice,
            buyNum: 1,
          },
          ...state.cartList,
        ]
      }
    },
  },
}
